import axios from 'axios'
//进度条
import NProgress from 'nprogress'

//在请求拦截中显示进度条nprogress.start()
//在响应拦截中隐藏进度条nprogress.done()
export function request(config) {

  return new Promise((resolve, reject) => {
    const req = axios.create({
      baseURL: 'http://127.0.0.1:8888/api/private/v1/',
      /*       timeout: 2000 */
    })
    req.interceptors.request.use(config => {
      // console.log(config);
      NProgress.start()
      config.headers.Authorization = sessionStorage.getItem('token')
      return config
    })
    req.interceptors.request.use(config => {
      NProgress.done()
      return config
    })
    req(config).then(res => {
        resolve(res)
      })
      .catch(err => {
        reject(err)
      })
  })

}